package com.legolas.api.utils;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/10/11 0011
 */
public class ResponseUtils {

    //controller返回：
    // return ResponseUtils.buildStringResponse("success",HttpStatus.OK);
    //OK(200, "OK"),
    //BAD_REQUEST(400, "Bad Request"),
    //NOT_FOUND(404, "Not Found"),
    //METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
    //NOT_ACCEPTABLE(406, "Not Acceptable"),
    //INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
    public static ResponseEntity buildStringResponse(Object obj, HttpStatus status) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "text/plain;charset=utf-8;");
        return new ResponseEntity(obj, responseHeaders, status);
    }

    public static ResponseEntity buildOKResponse(Object obj) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "text/plain;charset=utf-8;");
        return new ResponseEntity(obj, responseHeaders, HttpStatus.OK);
    }

    public static ResponseEntity build500Response() {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "text/plain;charset=utf-8;");
        return new ResponseEntity("服务端错误", responseHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
    }

    public static ResponseEntity build404Response() {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "text/plain;charset=utf-8;");
        return new ResponseEntity("访问页面不存在", responseHeaders, HttpStatus.NOT_FOUND);
    }


    public static ResponseEntity buildOKResponse() {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "text/plain;charset=utf-8;");
        return new ResponseEntity("操作成功", responseHeaders, HttpStatus.OK);
    }


}
